package com.huike.web.controller.system;

import com.huike.clues.domain.SysDictType;
import com.huike.clues.domain.dto.SysDictTypeQueryDTO;
import com.huike.clues.mapper.SysDictTypeMapper;
import com.huike.clues.service.ISysDictTypeService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/system/dict/type")
public class SysDictTypeController extends BaseController {

    @Autowired
    private ISysDictTypeService iSysDictTypeService;

    @GetMapping("/list")
    public TableDataInfo list(SysDictTypeQueryDTO sysDictTypeQueryDTO) {
        startPage();
        List<SysDictType> list = iSysDictTypeService.selectDictTypeList(sysDictTypeQueryDTO);
        return getDataTable(list);
    }
    /**
     * 获取字典选择框
     */
  /*  @GetMapping("/optionselect")
    public AjaxResult optionselect(){
        return AjaxResult.success(iSysDictTypeService.listdict());
    }*/

    /**
     * 新增字典类型
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysDictType sysDictType) {
        iSysDictTypeService.add(sysDictType);
        return AjaxResult.success();
    }

    /**
     * 查询字典类型详细信息
     */
    @GetMapping("/{dictId}")
    public AjaxResult getInfo(@PathVariable Integer dictId) {
        SysDictType sysDictType = iSysDictTypeService.getById(dictId);
        return AjaxResult.success(sysDictType);
    }

    /**
     * 修改字典类型
     */
    @PutMapping()
    public AjaxResult updatebyid(@RequestBody SysDictType sysDictType) {
        iSysDictTypeService.updatedicttype(sysDictType);
        return AjaxResult.success();
    }

    /**
     * 删除字典类型
     */
    @DeleteMapping("/{dictIds}")
    public AjaxResult remove(@PathVariable String dictIds) {
        iSysDictTypeService.removetypeAndDate(dictIds);
        return AjaxResult.success();
    }

    /**
     * 清空缓存
     */
    @DeleteMapping("/clearCache")
    public AjaxResult clearCache() {
        iSysDictTypeService.clearCache();
        return AjaxResult.success();
    }
}
